package top.eggcode.common.lang;

import lombok.Data;

import java.util.function.BiConsumer;
import java.util.function.Consumer;

/**
 * Title:
 * Description: TODO
 * Date: 2021/6/5 8:27
 *
 * @author JiaQi Ding
 * @version 1.0
 */
@Data
public class Promise<T> {


    private BiConsumer<Consumer<T>, Consumer<Object>> function;


    public Promise(BiConsumer<Consumer<T>, Consumer<Object>> function) {
        this.function = function;
    }

    public void then(Consumer<T> resolve, Consumer<Object> reject) {
        this.function.accept(resolve, reject);
    }

    public void then(Consumer<T> resolve) {

        this.function.accept(resolve, null);
    }

}
